/*
 * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: CC0-1.0
 */

#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
#include "driver/gpio.h"


#include "eink.h"
#include "EPD_Test.h"

#define EINK_TASK_STACK_SIZE 2048
#define EINK_TASK_PRIORITY 5

#define DEBUG_TASK_STACK_SIZE 1024
#define DEBUG_TASK_PRIORITY 5

static TaskHandle_t eink_task_h;
static TaskHandle_t debug_task_h; 

void eink_task(void *arg)
{
    EPD_test();
    while(1)
    {
        vTaskDelay(pdMS_TO_TICKS(3000));
        printf(".\n");
    }
}

void debug_task(void *arg)
{
    vTaskDelay(pdMS_TO_TICKS(5000));
    while(1)
    {
        // printf("GPIO %d : %d\n", EINK_PIN_NUM_CS, gpio_get_level(EINK_PIN_NUM_CS));
        // printf("GPIO %d : %d\n", EINK_PIN_NUM_RST, gpio_get_level(EINK_PIN_NUM_RST));
        printf("GPIO %d : %d\n", EINK_PIN_NUM_BUSY, gpio_get_level(EINK_PIN_NUM_BUSY));
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

void app_main(void)
{
    BaseType_t rc;
    eink_spi_init();

    rc = xTaskCreate(eink_task, "eink_task", EINK_TASK_STACK_SIZE, NULL, EINK_TASK_PRIORITY, &eink_task_h);
    assert(rc == pdPASS);

    // rc = xTaskCreate(debug_task,
    //                 "debug_task",
    //                 DEBUG_TASK_STACK_SIZE,
    //                 NULL,
    //                 DEBUG_TASK_PRIORITY,
    //                 &debug_task_h);
    // assert(rc == pdPASS);
    while(1)
    {
        vTaskDelay(pdMS_TO_TICKS(3000));
    }
}
